package com.njbw.common;

import com.njbw.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 帮我们实现的切面方式，也可以直接使用 Aop
 */
@RestControllerAdvice
public class ExceptionAdapterController {

    /**
     * 运行时异常统一拦截
     */
    @ExceptionHandler({RuntimeException.class})
    public Result<?> runtimeException(RuntimeException exception) {
        exception.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler({Exception.class})
    public Result<?> exception(Exception exception) {
        exception.printStackTrace();
        return Result.fail();
    }
}
